// 1.使用table_to_sheet():
$("#excelOutput").click(function() {
    var rote = $("#rote").val(); //获取毛利率 直接获取数据
    var Server_rote = $("#Server_rote").val(); //获取服务费率
    var sid = $("#sid").html(); //获取sid
    var cname = getCookie("cname");
    var userType = getCookie("userType");
    var tmp = $("#addForm").serializeArray(); //表单序列化 = > 直接将表单的数据内容提取为查询字符串格式(键 = 值)
    var formatData1 = formatData(tmp); //格式化input数据
    var formatData3 = JSON.stringify(formatData1); //转字符串json
    var formatData4 = JSON.parse(formatData3); //转json,
    var shortformatData = remove_empty(formatData4); //删除空数据字段，计算有效字段长度，添加json字段到数组
    var projectInfo = " SID:" + sid + " 毛利率:" + rote + "," + " 质保年利率:" + Server_rote + ", 核算工程师:" + cname;
    // console.log("exclOutput", shortformatData);

    // 要导出的json数据
    const jsonData = [{
            1: "",
            boxName2: "品号",
            phone: "S-A-24-21-0-1",
            email: "B-A-24-21-0-1",
        },
        {
            1: "",
            boxName2: "尺寸",
            phone: "1420*1880*450",
            email: "650*1880*450",
        },
        {
            1: "",
            boxName3: "数量",
            phone: "10",
            email: "20",
        },
        {
            1: "",
            boxName4: "不含税成本(单价)",
            phone: "1232.00",
            email: "892.00",
        },
        {
            1: "",
            boxName5: "含税单价",
            phone: "2345.89",
            email: "945.00",
        },
        {
            1: "",
            boxName5: "净利率",
            phone: "28%",
            email: "25%",
        },
        {
            1: "",
            boxName5: "软件费用",
            phone: "1234567.89",
            email: "3456.00",
        },
        {
            1: "",
            boxName5: "硬件定制费",
            phone: "1234567.89",
            email: "123456.00",
        },
        {
            1: "",
            boxName5: "总报价",
            phone: "123456789",
            email: " ",
        },
    ];
    // 列标题，逗号隔开，每一个逗号就是隔开一个单元格
    let str = `项目信息:,${projectInfo}\n\r\t,柜型名称,柜型1,柜型2,柜型3,柜型4,柜型5,柜型6,柜型7,柜8,柜型9,柜型10,\n`;
    // 增加\t为了不让表格显示科学计数法或者其他格式
    for (let i = 0; i < jsonData.length; i++) {
        for (const key in jsonData[i]) {
            str += `${jsonData[i][key] + "\t"},`;
        }
        str += "\n";
    }
    // encodeURIComponent解决中文乱码
    const uri = "data:text/csv;charset=utf-8,\ufeff" + encodeURIComponent(str);
    // 通过创建a标签实现
    const link = document.createElement("a");
    link.href = uri;
    // 对下载的文件命名
    link.download = "新增标准项目核价数据.xlsx";
    link.click();
    //   };
});